<?php
/**
 * Created by PhpStorm.
 * User: 96151
 * Date: 2019/3/11
 * Time: 22:59
 */

namespace app\common\service\SwooleJob;

use app\common\model\BookModel;
use app\common\model\ChapterModel;
use app\common\service\ElkLog;
use app\common\service\SwooleJob;

class WeChatPushBook
{
    /**
     * 微信推送队列
     */
    public static function BookUpdatePushJobs( $id )
    {
        SwooleJob::push( SwooleJob::$MY_JOBS ,__CLASS__,"BookUpdatePush" , array( $id ) );
    }

    /**
     * 检测到更新推送
     */
    public function BookUpdatePush( $id )
    {
        ElkLog::save( array( "message" => "success", "id" => $id ) );
        $Chapter = new ChapterModel();

        // 查询文章
        $data = $Chapter->where( "id={$id}" )->find()->toArray();
        if ( !$data ){
            return false;
        }

        // 获取小说
        $Book = new BookModel();
        $book_data = $Book->get_data_by_id( $data['book_id'] );

        ElkLog::save( array( "message" => "BookUpdatePush", "data" => $data ,"book_data" => $book_data ) );
    }

}